local mashuo = fk.CreateSkill{
  name = "hanqing__mashuo",
}

Fk:loadTranslationTable{
  ["hanqing__mashuo"] = "马说",
  [":hanqing__mashuo"] = "每阶段限一次，当你摸牌时，若摸牌数不为1，则改为摸一张牌，令一名其他角色摸两张牌。然后若你的手牌均为红色，"..
  "你可以展示手牌再摸一张牌，弃置一名其他角色一张牌。",

  ["#hanqing__mashuo-choose"] = "马说：令一名其他角色摸两张牌",
  ["#hanqing__mashuo-show"] = "马说：是否展示手牌，再摸一张牌并弃置一名其他角色一张牌？",
  ["#hanqing__mashuo2-choose"] = "马说：弃置一名其他角色一张牌",
  ["#hanqing__mashuo-discard"] = "马说：弃置 %dest 一张牌",
}

mashuo:addEffect(fk.BeforeDrawCard, {
  anim_type = "control",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(mashuo.name) and data.num ~= 1 and
      player:usedSkillTimes(mashuo.name, Player.HistoryPhase) == 0
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:drawCards(1, mashuo.name)
    local targets = room:getOtherPlayers(player, false)
    if player.dead or #targets == 0 then return end
    local to = room:askToChoosePlayers(player, {
      min_num = 1,
      max_num = 1,
      targets = targets,
      skill_name = mashuo.name,
      prompt = "#hanqing__mashuo-choose",
      cancelable = false,
    })[1]
    to:drawCards(2, mashuo.name)
    if player.dead or player:isKongcheng() then return end
    if table.every(player:getCardIds("h"), function (id)
      return Fk:getCardById(id).color == Card.Red
    end) and
    room:askToSkillInvoke(player, {
      skill_name = mashuo.name,
      prompt = "#hanqing__mashuo-show",
    }) then
      player:showCards(player:getCardIds("h"))
      if player.dead then return end
      player:drawCards(1, mashuo.name)
      targets = table.filter(room:getOtherPlayers(player, false), function (p)
        return not p:isNude()
      end)
      if player.dead or #targets == 0 then return end
      to = room:askToChoosePlayers(player, {
        min_num = 1,
        max_num = 1,
        targets = targets,
        skill_name = mashuo.name,
        prompt = "#hanqing__mashuo2-choose",
        cancelable = false,
      })[1]
      local card = room:askToChooseCard(player, {
        target = to,
        flag = "he",
        skill_name = mashuo.name,
        prompt = "#hanqing__mashuo-discard::"..to.id,
      })
      room:throwCard(card, mashuo.name, to, player)
    end
    return true
  end,
})

return mashuo
